package ch10.shili;

public class S04_WorkThread implements Runnable{
    @Override
    public void run() {
        Thread t = Thread.currentThread();
        System.out.println(t.getName()+"开始摘苹果");
        for(int i = 0; i < 5; i++){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(t.getName()+" 进度: 第" + (i+1)+"棵");
        }
        System.out.println(t.getName()+"已经完成采摘任务");
    }
}

class RunnableTest{
    public static void main(String[] args) {
        S04_WorkThread work1 = new S04_WorkThread();
        S04_WorkThread work2 = new S04_WorkThread();
        Thread t1 = new Thread(work1);
        Thread t2 = new Thread(work2);
        t1.setName("码农C");
        t2.setName("码农D");
        t1.start();
        t2.start();
    }
}